import { AclType } from "@/core/pinia/interface";
import { useAclHooks } from "@/core/pinia/store/acl.store";
import type { Directive, DirectiveBinding } from "vue";

export const acl: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding<AclType>) {
    const { value } = binding;
    const acl = useAclHooks();
    if (value) {
      !acl.canAbility(value) && el.parentNode?.removeChild(el);
    }
  }
};
